<template>
    <div>
        <Particles id="tsparticles" :options="options" />

        <div class="formContainer">
            <h3>企业门户管理系统</h3>
            <el-form ref="loginFormRef" :model="loginForm" status-icon :rules="loginRules" label-width="80px"
                class="loginForm">
                <el-form-item label="用户名" prop="username">
                    <el-input v-model="loginForm.username" autocomplete="off" />
                </el-form-item>
                <el-form-item label="密码" prop="password">
                    <el-input v-model="loginForm.password" type="password" autocomplete="off" />
                </el-form-item>
                <el-form-item style="margin-top: 50px;">
                    <el-button style="width: 30%;" color="#626aef" @click="submitForm(ruleFormRef)"
                        size="large">登录</el-button>
                </el-form-item>
            </el-form>
        </div>
    </div>
</template>

<script setup>


import { reactive, ref } from 'vue';
import { useRouter } from 'vue-router';
import axios from 'axios';
import { ElMessage } from 'element-plus'
import { useStore } from 'vuex';

const store = useStore()

const loginForm = reactive({
    username: '',
    password: ''
})

const loginFormRef = ref()

const loginRules = reactive({
    username: [{
        required: true, message: '请输入用户名', trigger: 'blur'
    }],
    password: [{
        required: true, message: '请输入密码', trigger: 'blur'
    }]
})

const router = useRouter()

const submitForm = () => {
    loginFormRef.value.validate((valid) => {
        console.log(valid)
        if (valid) {
            axios.post("/adminapi/user/login", loginForm).then(res => {
                console.log(res.data)
                console.log(88888)
                if (res.data.actionType == 'ok') {
                    store.commit('changeUserInfo', res.data.data)
                    store.commit('changeGetRouter', false)
                    router.push('/index')
                } else {
                    ElMessage.error(res.data.error)
                }
            })
        }
    })
}

// 配置
const options = {
    background: {
        color: {
            value: '#1f2040'
        }
    },
    fpsLimit: 120,
    interactivity: {
        events: {
            onClick: {
                enable: true,
                mode: 'push'
            },
            onHover: {
                enable: true,
                mode: 'repulse'
            },
            resize: true
        },
        modes: {
            bubble: {
                distance: 400,
                duration: 2,
                opacity: 0.8,
                size: 40
            },
            push: {
                quantity: 4
            },
            repulse: {
                distance: 200,
                duration: 0.4
            }
        }
    },
    particles: {
        color: {
            value: '#ed4845'
        },
        links: {
            color: '#fffef8',
            distance: 150,
            enable: true,
            opacity: 0.5,
            width: 1
        },
        collisions: {
            enable: true
        },
        move: {
            direction: 'none',
            enable: true,
            outModes: {
                default: 'bounce'
            },
            random: false,
            speed: 6,
            straight: false
        },
        number: {
            density: {
                enable: true,
                area: 800
            },
            value: 80
        },
        opacity: {
            value: 0.5
        },
        shape: {
            type: 'circle'
        },
        size: {
            value: { min: 1, max: 5 },
        }
    },
    detectRetina: true
}
</script>

<style lang="scss" scoped>
.formContainer {
    width: 500px;
    height: 300px;
    position: fixed;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    background-color: rgba($color: #0f1423, $alpha: .5);
    color: #feba07;
    text-align: center;
    padding: 20px;

    h3 {
        font-size: 30px;

    }

    .loginForm {
        margin-top: 20px;
    }
}

::v-deep .el-form-item__label {
    color: #feba07;
}
</style>